package vaani.internal.beagle;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

/**
 *
 * @author sourcemorph
 */
public class Interface {
    private static String query;
    private static Vector<Result> results;

    public static void makeQuery(String q) {
        query = q;
        results = new Vector<Result>();
        Process findSpace;
        try {
            findSpace = Runtime.getRuntime().exec("beagle-query " + query);
            BufferedReader reader = new BufferedReader(new InputStreamReader(findSpace.getInputStream()));
            String temp;
            while((temp = reader.readLine()) != null) {
                results.add(new Result(temp));
            }
        } catch(IOException ex) {
            ex.printStackTrace();
        }
    }

    public static int numHits() {
        if(!results.equals(null)) {
            return results.size();
        }
        else return -1;
    }

    public static Vector<Result> getHits() {
        if(!results.equals(null)) {
            return results;
        }
        else return null;
    }
}
